import { Injectable } from "@angular/core";
import { Platform } from "@ionic/angular";
import { I18N } from "./i18n.config";
import { LocalStorage } from "./local-storage.service";

@Injectable()
export class Global {

	static FIRST_LAUNCH = "FIRST_LAUNCH";
	static APP_ID = "id1551346700";
	static IAP = "wenfc_admob";
	static TAGS = "TAGS";
	static BANNER_ID = "ca-app-pub-3289899656669935/6245311123";
	static INSERT_ID = "ca-app-pub-3289899656669935/6874020609";
	static VIDEO_READ_ID = "ca-app-pub-3289899656669935/8560289755";
	static VIDEO_WRITE_ID = "ca-app-pub-3289899656669935/2360663166";
	static VIDEO_SHARE_ID = "ca-app-pub-3289899656669935/2169091473";
	static VIDEO_SCAN_ID = "ca-app-pub-3289899656669935/5916764797";

	static LANGUAGE = "LANGUAGE";

	constructor(
		private platform: Platform,
		private localStorage: LocalStorage,
	) {
	}

	get needShowAd(): boolean {
		return !this.localStorage.getData(Global.IAP);
		// return false;
	}

	get isFree(): boolean {
		const date = this.localStorage.getData(Global.FIRST_LAUNCH).date;
		const now = new Date().getTime();
		return now < date;
	}

	get isDevice(): boolean {
		return this.platform.is("pwa") || this.platform.is("mobileweb");
	}

	chooseLanguage(language: string) {
		this.localStorage.setData(Global.LANGUAGE, language);
	}

	get language() {
		return this.localStorage.getData(Global.LANGUAGE);
	}

	translate(key: string) {
		const language = this.localStorage.getData(Global.LANGUAGE);
		switch (language) {
			case I18N.LANGUAGE_EN_US:
				return I18N.STR_EN_US[key];
			case I18N.LANGUAGE_CHN_S:
				return I18N.STR_CHN_S[key];
			default:
				return I18N.STR_EN_US[key];
		}
	}
}
